<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            选择库位
        </div>
    </header>
    <script id="workCellTemp" type="text/x-dot-template">

        {{~ it:value:index}}
        <li class="aui-list-item" onclick="setWorkCell('{{= it[index].workCellGid }}','{{= it[index].workCellCode }}','{{= it[index].workCellName }}');">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-title">{{= it[index].workCellCode }}:{{= it[index].workCellName }}</div>
            </div>
        </li>
        {{~}}

    </script>
    <div class="aui-content aui-margin-b-15" style="margin-top:60px;">
        <div class="aui-searchbar" id="search" style="position: relative;">
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search"></i>
                <div class="aui-searchbar-input">
                    <form action="javascript:doSearch();">
                        <input type="search" placeholder="请输入库位编码" id="workCellCodeS">
                    </form>
                </div>
                <!-- <i class="aui-iconfont aui-icon-roundclosefill" tapmode onclick="clearInput()"></i> -->
            </div>
            <div class="aui-btn aui-btn-primary" style="margin-right: 0.5rem;background-color: #03a9f4"
                onclick="doSearch()">搜索</div>
        </div>
        <ul class="aui-list aui-list-in" id="workCellList">

        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<!-- <script src="../script/zepto.min.js"></script> -->
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    apiready = function () {

        getworkCellList();

    };

    //查询仓库列表
    function getworkCellList() {

        //库内库间页面标识
        var flag = api.pageParam.flag;
        //取调入库位
        var relWorkCellGid = api.pageParam.relWorkCellGid;
        //取条码
        var tm = api.pageParam.tm;
        //取源目标标识（1源2目标）
        var workCellFlag = api.pageParam.workCellFlag;
        //取仓库GID  --入库出库业务用
        var workCenterGid = api.pageParam.workCenterGid;
        //操作类型--工单上料用
        var operateType = api.pageParam.operateType;
        //工单号--工单上料用
        var workOrderCode = api.pageParam.workOrderCode;
        //取库位编码  --库内转移业务用
        var kwcode = api.pageParam.kwcode;
        //取仓库类别
        var centerClass = api.pageParam.centerClass;

        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkCell";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                flag: flag, //库内库间标识（out_kn库内  out_kj库间）
                relWorkCellGid: relWorkCellGid, //调入库位
                tm: tm,
                centerClass: centerClass,//仓库类别
                kwcode: kwcode,
                workCellFlag: workCellFlag,
                workCenterGid: workCenterGid, //仓库GID  入库出库用
                operateType: operateType, //操作类型，工单上料用
                workOrderCode: workOrderCode, //工单号，工单上料用
                workCellCode: "",
                un: un
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var mydata = myobj.list;
                    var evaluation = doT.template($api.dom('#workCellTemp').innerHTML);
                    $api.dom('#workCellList').innerHTML = evaluation(mydata);
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("连接超时，请耐心等待");
            }
        });
    }

    //选则返回函数
    function setWorkCell(workCellGid, workCellCode, workCellName) {
        api.closeWin();
        var flag = api.pageParam.flag;
        var name = api.pageParam.name;
        //入库
        if ('in_rk' == flag) {
            api.execScript({
                name: name,
                script: 'setWorkCell("' + workCellGid + '","' + workCellCode + '","' + workCellName + '")'
            });


            //库内-库间转移
        } else if ('out_kn' == flag || "out_kj") {
            var workCellFlag = api.pageParam.workCellFlag;
            api.execScript({
                name: name,
                script: 'setWorkCell("' + workCellGid + '","' + workCellCode + '","' + workCellName + '","' + workCellFlag + '")'
            });
        }
    }

    //库位编码查询
    function doSearch() {
        var workCenterGid = api.pageParam.workCenterGid;
        //取库位编码  --库内转移业务用
        var kwcode = api.pageParam.kwcode;
        var workCellCodeS = $("#workCellCodeS").val();
        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkCell";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                flag: "search", //库内库间标识（out_kn库内  out_kj库间）
                relWorkCellGid: "", //调入库位
                tm: "",
                workCellFlag: "",
                kwcode: kwcode,
                workCenterGid: workCenterGid, //仓库GID  入库出库用
                workCellCode: workCellCodeS,
                un: un
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var mydata = myobj.list;
                    var evaluation = doT.template($api.dom('#workCellTemp').innerHTML);
                    $api.dom('#workCellList').innerHTML = evaluation(mydata);
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("连接超时，请耐心等待");
            }
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>